package tolgahan.albayrak.as3.reflection.converters
{
	import tolgahan.albayrak.as3.reflection.Primitives;
	import tolgahan.albayrak.as3.reflection.Type;

	public class NumberConverter extends TypeConverter
	{
		public function NumberConverter()
		{
			super();
		}
		override public function canConvertFrom(type:Type) : Boolean
		{
			return type && type.isPrimitive;
		}
		override public function canConverTo(type:Type) : Boolean
		{
			return type && type.isPrimitive;
		}
		
		override public function converFrom(object:Object) : *
		{
			return Number(object);
		}
		override public function convertTo(object:Object, type:Type) : *
		{
			object = Number(object);
			switch(type)
			{
				case Primitives.DateType:
					return new Date(object);
				case Primitives.IntType:
					return int(object);
				case Primitives.NumberType:
					return object;
				case Primitives.StringType:
					return String(object);
				case Primitives.UIntType:
					return uint(object);
			}
		}
	}
}